Skip to content

feat(preview): an optional key so only scanned devices get in - #108

Merged
flowtricks merged 1 commit into
flowtricks:mainfrom
SylvainDruaux:feat/lan-preview-key
Nov 28, 2026
Merged

flowtricks merged 1 commit into
flowtricks:mainfrom
SylvainDruaux:feat/lan-preview-key

Conversation

@SylvainDruaux

Copy link
Copy Markdown
Contributor

An optional key in the phone preview's QR code, so only the devices that scan it can open the preview, as discussed on Discord.

  • A settings gear beside Copy in the QR card, with one option: "Only via this code". Off by default, never saved (not in settings or .stacki).
  • On: main makes a random key and restarts the dev server with it in its environment. The QR code and Copy carry it; the shown address does not.
  • A device that opens the code's address gets an HttpOnly cookie and a redirect to the same page without the key. With the cookie it gets in; every other device on the Wi-Fi gets 403, Vite's live-reload WebSocket included.
  • This computer always passes (the canvas needs no key), and Stacki's own routes stay closed to other devices as before.
  • Every device that scans the code gets in (phone and iPad alike). Turning the option off and on makes a new key.

UI

  • The popover grows from 232 to 260 px for the gear; the QR tile grows from 208 to 236 px so it still fills it.
  • Changing the option keeps the card in place, dimmed, while the server restarts (no skeleton redraw).
  • Labels in all 18 catalogs.

Tests

  • Contract: access and key parsing, keyed phone URL.
  • Guard: verdicts, cookie bounds, and a real server reached through this machine's network address (403 without the code, 303 + cookie with it, WebSocket refused without the cookie).
  • Main: key life cycle (new key each time, dropped when off, closed or failed).
  • Popover (jsdom) and layout (Chromium).
  • npm run integration:lan against a real Astro dev server.
  • Checked by hand on an iPhone and an iPad, plus a device without the code.
  • Full gate: 1560/1560.

With the phone preview on, the dev server answers everyone on the Wi-Fi: Stacki's own routes are locked to this computer, but the site and everything Vite serves are open to any device on the same network. The QR card now has a settings gear beside Copy with one option, "Only via this code". Off by default and never saved (not in settings, not in .stacki): turning the preview off, closing the project or quitting forgets it.

Turned on, main makes a random key (32 bytes, base64url) and restarts the dev server with it in its environment only (STACKI_PREVIEW_KEY). The QR code and Copy carry it as a query parameter; the shown address and the code's spoken label never do. The loopback guard answers the code's address with an HttpOnly, SameSite=Lax cookie and a 303 to the same page without the key, so it leaves the address bar and the history; the cookie then lets that device in, and every other request from the network gets 403, Vite's live-reload WebSocket included (an upgrade listener before Vite's). This computer always passes, so the canvas needs no key, and Stacki's routes stay closed to every other device, key or not. Every device that scans the code gets in (a phone and an iPad alike); turning the option off and on makes a new key, which locks out the devices that scanned an older code. Keys are compared in constant time.

The request and state of dev:setNetwork carry the access (open, or key with its key), parsed at the boundary. Changing the access while on keeps the card in place, dimmed, instead of redrawing it as skeletons. The popover grows from 232 to 260 px for the gear, and the QR tile from 208 to 236 px so it still fills it.

Tests: the contract (access, key format), the guard's verdicts, cookie bounds and a real server reached through this machine's own network address (403 without the code, 303 and cookie with it, the WebSocket refused without the cookie), main's key life cycle, the popover (gear, setting, keyless display, keyed Copy, no redraw), the Chromium layout, and the LAN integration run against a real Astro server.
@flowtricks
flowtricks merged commit 87a2e94 into flowtricks:main Nov 28, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants